#-*- codeing = utf-8 -*-
#@Time : 2020/9/22 19:44
#@Author : 阳某
#@File : 验证码.py
#@Software : PyCharm

from PIL import Image,ImageFilter,ImageFont,ImageDraw
import random
import string
print(string.ascii_letters) #大小写字母
print(random.choice(string.ascii_letters)) #大小写字母
# print(string.ascii_lowercase)#小写字母
# print(string.ascii_uppercase)  #大写字母
# 生成随机的字母

# 随机生成字母和数字
def gettandle(num,mary):       #num表示生成几位，mary表示生成几组
    for x in range(mary):
        s = ''
        for i in range(num):
            n = random.randint(1,2)     #n只能是1或者2，n=1生成数字，n=2，随机生成字母
            if n==1:
                numb = random.randint(0,9)
                s += str(numb)
            else:
                # 65-90:A-Z, 97-
                # s+=str(chr(random.randint()))
                s+=str(random.choice(string.ascii_letters))
    return s
# 随机生成RGB颜色
def rndColor():
    return (random.randint(64,255),random.randint(64,255),random.randint(64,255))

def rndColor2():
    return (random.randint(32,127),random.randint(32,127),random.randint(32,127))



width = 60*4
height = 60
image = Image.new('RGB',(width,height),(0,0,0))     #创建一个画布
# 指定字体和字体大小
font = ImageFont.truetype('MinionPro-BoldIt.otf',36)
draw = ImageDraw.Draw(image)
# 填充像素点
for j in range(width):
    for k in range(height):
        draw.point((j,k),fill=rndColor())
for x in range(4):
    # 落笔点，写的内容，字体,填充字体颜色
    draw.text((60*x+10,14),gettandle(1,4),font = font,fill=rndColor2())   #从左上角开始落笔写
image.show()


'''
def rndChar():
    # print(chr(65))      # 65-A，97-a
    return chr(random.randint(65,90))
width = 60*4
height = 60
image = Image.new('RGB',(width,height),(255,255,255))     #创建一个画布
# 指定字体和字体大小
font = ImageFont.truetype('MinionPro-BoldIt.otf',36)
draw = ImageDraw.Draw(image)
for x in range(4):
    # 落笔点，写的内容，字体,填充字体颜色
    draw.text((60*x+10,14),rndChar(),font = font,fill=(0,0,0))   #从左上角开始落笔写
image.show()
'''